{template:header}
{template:usercp_menu}
<script language='JavaScript' type="text/javascript">
//<![CDATA[
var attach_maxnum = {$upload['maxnum']};
var attach_num = 0;
var thisforum = 'pm';
tag_prompt = "{$lang['tagprompt']}:";
font_formatter_prompt = "{$lang['formatprompt']} - ";
link_text_prompt = "{$lang['textprompt']}:";
link_url_prompt = "{$lang['urlprompt']}:";
link_email_prompt = "{$lang['emailprompt']}:";
list_type_prompt = "{$lang['typeprompt']}";
list_item_prompt = "{$lang['itemprompt']}";

function smilie_pop()
{
	window.open('misc.php{sessionurl}do=icon','misc','width=500,height=300,resizable=yes,scrollbars=yes');
}

function getMessageLength() {
 mxeGet();
 return calculate_byte(mxeTxH.value);
}

var postmaxchars = "{$bboptions['maxpostchars']}";
var postminchars = "{$bboptions['minpostchars']}";
var override = "";
function submit_form(isMsg) {
 mxeGet();
  if (isMsg == 1) {
   if (document.mxbform.title.value.length < 2) {
     alert("{$lang['mustinputtitle']}");
     reinit();
     return false;
   }
  }
  if (document.mxbform.post.value=="") {
   alert("{$lang['mustinputcontent']}");
   reinit();
   return false;
  }
  return messagetolong();
}

function checklength() {
 if (postmaxchars != 0) message = "{$lang['allowmostlength']} "+postmaxchars+" {$lang['chars']}";
 else message = "";

 var messageLength = getMessageLength();
 alert("{$lang['youhaveinput']} "+messageLength+" {$lang['chars']}" + message);
}

function messagetolong() {
 $('submitform').disabled = true;
 var messageLength = getMessageLength();
 if ((postmaxchars != 0) && (messageLength > postmaxchars)) {
  alert("{$lang['postcharstoolong']} "+postmaxchars+" {$lang['chars']}{$lang['youhaveinput']} "+messageLength+" {$lang['chars']}");
  reinit();
  return false;
  } else if ((postminchars != 0) && (messageLength < postminchars)) {
   alert("{$lang['postcharstooshort']} "+postminchars+" {$lang['chars']}{$lang['youhaveinput']} "+messageLength+" {$lang['chars']}");
  reinit();
   return false;
  } else {
  document.mxbform.submit();
 }
}

function sendattach() {
	var attachform = $('mxb_attachform');
	if (attachform && attachform.attachment0.value) {
		attachform.attach_num.value = attach_num;
		attachform.submit();
		$('submitform').disabled = true;
		if ($('preview')) {
			$('preview').disabled = true;
		}
		var info = "<font color=red>"+lang_g['g_refering']+"</font>";
		$('attachbutton').innerHTML = info;
		attach_num = 0;
	} else {
		alert(lang_g['g_selectat']);
	}
}

function removeattach(id) {
	var okdelete = confirm("{$lang['deleteattachs']}");
	if ( okdelete == true ) {
		if ( id != "" ) {
			$('attach_do').value = 'delete';
			document.mxb_attachform.removeattachid.value = id;
			var attachform = $('mxb_attachform');
			if (attachform && attachform.attachment0.value) {
				sendattach();
			} else {
				attachform.submit();
				$('submitform').disabled = true;
				if ($('preview')) {
					$('preview').disabled = true;
				}
				var info = "<font color=red>"+lang_g['g_refering']+"</font>";
				$('attachbutton').innerHTML = info;
				attach_num = 0;
			}
			document.mxb_attachform.removeattachid.value = 0;
		}
	} else {
		document.mxb_attachform.removeattachid.value = 0;
		return false;
	}
}

function check_form_attach() {
	var attachform = $('mxb_attachform');
	var formValue = document.mxbform;
	mxeGet();
	if (attachform && attachform.attachment0.value) {
		attachform.is_send.value = 1;
		sendattach();
	} else {
		submit_form(1);
	}
}

function createattach(obj)
{
	var newelement;
	if (obj.id == 'attachment'+attach_num)  {
		attach_num= attach_num + 1;
		if (attach_num == attach_maxnum) {
			return;
		}
		newinput = document.createElement('input');
		newinput.type = 'file';
		newinput.name = 'attachment'+attach_num;
		newinput.id = 'attachment'+attach_num;
		newinput.size = 30;
		newinput.className = 'input_big';
		newinput.onchange = function(){createattach(this)};
		newelement = document.createElement('div');
		newelement.appendChild(newinput);
		document.getElementById('attachdiv').appendChild(newelement);
	}
}

function reinit()
{
	 if ($('attachbutton')) {
		 $('attachbutton').innerHTML = '<input type="button" name="uploadbutton" id="uploadbutton" value=" {$lang['_addattach']} " class="input_big" onclick="sendattach();" />';
	 }
	 $('submitform').disabled = false;
	 if ($('preview')){
	 	 $('preview').disabled = false;
	 }
}
//]]>
</script>
<script type="text/javascript" src="./editor/bbcode.js"></script>

<div id="ucp_content">
	<if="$errors">
	<div class="ucp">
		<div id='errors'>
			<h3>{$lang['pmsenderrors']}</h3>
			<p>{$errors}</p>
			<p>{$lang['correcterrors']}</p>
		</div>
	</div>
	</if>
	<h3>{$lang['writenewpm']}</h3>
	<form action="private.php" method="post" name='mxbform' id='mxbform' enctype='multipart/form-data' onsubmit="return submit_form(1);">
		<input type='hidden' name='s' value='{sessionid}' />
		<input type='hidden' name='do' value='sendpm' />
		<input type='hidden' name='posthash' value='{$posthash}' />
		<input type='hidden' name='MAX_FILE_SIZE' value='{$bbuserinfo['attachlimit']}' />
		<input type="hidden" name="pagetype" id="pagetype" value="msg"/>
		<em>{$lang['recipients']}</em>
		<p>{$lang['recipientsname']}&nbsp;{$lang['mostusers']}:{$sendmax}&nbsp;{$lang['semisplit']}</p>
		<div class="ucp">{$contact}<input type='text' name='username' size='50' value='{$username}' tabindex="1" class='input_normal' /></div>
		<em>{$lang['pmtitle']}</em>
		<div class="ucp"><input type='text' name='title' size='40' tabindex="2" maxlength='40' value='{$title}' class='input_normal' /></div>
		<em>{$lang['postcontent']}</em>
		<div class="ucp">
			<table cellpadding='0' cellspacing='0' width='100%' border='0'>
			<tbody>
				<tr>
				<td>
					<textarea id='post' name='post' style="width:600px;height:400px;" rows="" cols="">{$content}</textarea>
				</td>
				</tr>
			</tbody>
			</table>
		</div>
		<em>{$lang['_options']}</em>
		<ul class="ucp">
			<li>
				<label for='savecopy'>
					<input type='checkbox' name='savecopy' id='savecopy' value='1' />
					{$lang['bebackup']}
				</label>
			</li>
			<li>
				<label for='addtracking'>
					<input type='checkbox' name='addtracking' id='addtracking' value='1' />
					{$lang['usereceipt']}
				</label>
			</li>
			<li>
				<label for='allowsmile'>
					<input type='checkbox' name='allowsmile' id='allowsmile' value='1' checked='checked'/>
					{$lang['allowsmilies']}
				</label>
			</li>
			<li>
				<label for='parseurl'>
					<input type='checkbox' name='parseurl' id='parseurl' value='1' checked='checked'/>
					{$lang['parseurl']}
				</label>
			</li>
		</ul>
		<input type="hidden" name="checkurl" value="0" />
		<if="is_array($creditsingle_list)">
		<em>{$lang['_singleaction_will']}</em>
		<ul class='ucp'>
			<foreach="$creditsingle_list AS $credit">
			<li>{$credit[0]}&nbsp;<strong>{$credit[1]}</strong></li>
			</foreach>
		</ul>
		</if>
		<if="is_array($creditgroup_list)">
		<em>{$lang['_groupaction_will']}</em>
		<ul class='ucp'>
		<foreach="$creditgroup_list AS $credit">
			<li>{$credit[0]}&nbsp;<strong>{$credit[1]}</strong></li>
		</foreach>
		</ul>
		</if>
	</form>
	<if="$show['upload'] AND !$bboptions['remoteattach']">
	<form action="attach.php" method="post" enctype="multipart/form-data" id="mxb_attachform" name="mxb_attachform" target="attachframe">
		<input type='hidden' name='s' value='{$sessionid}' />
		<input type='hidden' name='posthash' value='{$posthash}' />
		<input type='hidden' name='MAX_FILE_SIZE' value='{$bbuserinfo['attachlimit']}' />
		<input type="hidden" name="do" id="attach_do" value="upload" />
		<input type="hidden" name="upload" value="1" />
		<input type="hidden" name="removeattachid" id="removeattachid" value="0" />
		<input type="hidden" name="is_send" id="is_send" value="0" />
		<input type="hidden" name="attach_num" id="attach_num" value="0" />
		<em>{$lang['_attachment']}</em>
		<p>{$lang['attachmentleft']}: {$upload['left']}</p>
		<div class='ucp'>
			<div id="attachdiv"><div><input type='file' size='30' name='attachment0' id='attachment0' class='input_big' onchange="createattach(this);" /></div></div>
			<span id="attachbutton"><input type="button" name="uploadbutton" id="uploadbutton" value=" {$lang['addattachment']} " class='input_big' onclick='sendattach();' /></span>
			<div id='showattach'>{$upload['tmp']}</div>
			<iframe src="about:blank" width="0" height="0" frameborder="0" id="attachframe" name="attachframe"></iframe>
		</div>
	</form>
	</if>
	<div class='ucp item_change' align="center">
		<input type="button" id="sub_form" onclick='submit_form(1);' style="visibility:hidden;display:none" />
		<input type="button" value="{$lang['sendpm']}" tabindex='4' accesskey='s' name='submitform' id='submitform' class='input_big' onclick="check_form_attach()" />
	</div>
</div>

{template:footer}